package bravo.xc.com.xc_bravo_android.operation.person_center;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import bravo.xc.com.xc_bravo_android.R;
import bravo.xc.com.xc_bravo_android.base.BaseMVPActivity;
import bravo.xc.com.xc_bravo_android.beans.SendCodeBeans;
import bravo.xc.com.xc_bravo_android.operation.bankcard.bankcard.BankcardActivity;
import bravo.xc.com.xc_bravo_android.operation.message.MessageActivity;
import bravo.xc.com.xc_bravo_android.operation.login.LoginActivity;
import bravo.xc.com.xc_bravo_android.operation.order.OrderActivity;
import bravo.xc.com.xc_bravo_android.operation.transaction.TransactionActivity;
import bravo.xc.com.xc_bravo_android.operation.withdraw.withdrawmain.WithdrawActivity;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.jpush.android.api.JPushInterface;

import static bravo.xc.com.xc_bravo_android.beans.AliaBeans.LOGINOUTREAL;

public class PersonalCenterActivity extends BaseMVPActivity<PersonalCenterContract.PersonalCenterView,PersonalCenterContract.PersonalCenterPresenter> implements View.OnClickListener,PersonalCenterContract.PersonalCenterView {
    private ImageView img_bell;
    private TextView tv_bussinessName;//商家名
    private LinearLayout layout1;//交易信息
    private LinearLayout layout2;//我的订单
    private LinearLayout layout3;//提现中心
    private LinearLayout layout4;//我的银行卡
    private Button btn_logout;//退出登录
    private ProgressDialog progressDialog;
    public static SendCodeBeans sendCodeBeans;
    public static PersonalCenterContract.PersonalCenterPresenter centerPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.img_bell:
                Intent intent=new Intent(PersonalCenterActivity.this, MessageActivity.class);
                startActivity(intent);
                break;
            case R.id.layout1:
                Intent intent1=new Intent(PersonalCenterActivity.this, TransactionActivity.class);
                startActivity(intent1);
                break;
            case R.id.layout2:
                Intent intent2=new Intent(PersonalCenterActivity.this, OrderActivity.class);
                startActivity(intent2);
                break;
            case R.id.layout3:
                Intent intent3=new Intent(PersonalCenterActivity.this, WithdrawActivity .class);
                startActivity(intent3);
                break;
            case R.id.layout4:
                Intent intent4=new Intent(PersonalCenterActivity.this,BankcardActivity.class);
                startActivity(intent4);
                break;
            case R.id.btn_logout:
                showProgress(true);
                centerPresenter = new PersonalCenterPresenter();
                centerPresenter = presenter;
                JPushInterface.deleteAlias(this,LOGINOUTREAL);
                break;
        }
    }

    @Override
    public void removeUserInfo() {
        getSharedPreferences("isLogin",MODE_PRIVATE).edit().putBoolean("flag",false).commit();
        getSharedPreferences("UserInfo",MODE_PRIVATE).edit().clear();
    }


    @Override
    protected PersonalCenterContract.PersonalCenterPresenter createPresnter() {
        return new PersonalCenterPresenter();
    }

    @Override
    protected void initView() {
        img_bell=(ImageView)findViewById(R.id.img_bell);
        tv_bussinessName=(TextView)findViewById(R.id.tv_bussinessName);
        layout1=(LinearLayout)findViewById(R.id.layout1);
        layout2=(LinearLayout)findViewById(R.id.layout2);
        layout3=(LinearLayout)findViewById(R.id.layout3);
        layout4=(LinearLayout)findViewById(R.id.layout4);
        btn_logout=(Button)findViewById(R.id.btn_logout);

        img_bell.setOnClickListener(this);
        layout1.setOnClickListener(this);
        layout2.setOnClickListener(this);
        layout3.setOnClickListener(this);
        layout4.setOnClickListener(this);
        btn_logout.setOnClickListener(this);

        progressDialog = new ProgressDialog(this,R.style.MyDialogStyle);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setCanceledOnTouchOutside(false);
    }

    @Override
    public void showProgress(boolean show) {

        if(progressDialog.isShowing()){
            progressDialog.dismiss();
            Log.e("@@showProgress","isShowing:dismiss");
        }
        if(show){
            progressDialog.show();
        }else {
            progressDialog.dismiss();
            Log.e("@@showProgress","dismiss");
        }

    }

    @Override
    protected void initData() {
        tv_bussinessName.setText(getSharedPreferences("UserInfo",MODE_PRIVATE).getString("shopname",null));
        sendCodeBeans = new SendCodeBeans();
        sendCodeBeans.setUsername(getSharedPreferences("UserInfo",MODE_PRIVATE).getString("username",null));
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_personal_center;
    }

    @Override
    protected Unbinder getBinder() {
      return ButterKnife.bind(this);
    }

    @Override
    protected void onChildDestroy() {
        presenter.onDetached();
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(PersonalCenterActivity.this,str,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void toNewActivity(int intent) {
        Intent toNewActivity;
        switch (intent){
            case 0:
                toNewActivity = new Intent(PersonalCenterActivity.this,LoginActivity.class);
                startActivity(toNewActivity);
                this.finish();
                break;
            default:
                toNewActivity = new Intent(PersonalCenterActivity.this,LoginActivity.class);
                startActivity(toNewActivity);
                break;
        }

    }
}
